﻿// RunUO script: Skill Ball
// Copyright (c) 2003 by Wulf C. Krueger &lt;wk@mailstation.de>
//
// This script is free software; you can redistribute it and/or modify

// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License applies.
//

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of

// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// Please do NOT remove or change this header.


using System;
using Server.Network;
using Server.Items;
using Server.Gumps;
namespace Server.Items
{
    public class SkillBallOld : Item
    {
        private double m_SkillBonus = 100;
        private string m_BaseName = "a skill ball";
        public bool GumpOpen = false;
        [CommandProperty(AccessLevel.GameMaster)]
        public double SkillBonus
        {
            get
            {
                return m_SkillBonus;
            }
            set
            {
                m_SkillBonus = value;
                UpdateName();

            }
        }
        [Constructable]
        public SkillBallOld(int SkillBonus)
            : base(6249)
        {
            m_SkillBonus = SkillBonus;
            //Name = m_BaseName + Convert.ToString(SkillBonus);
            UpdateName();
            //Blessed = true;
            Movable = false;
        }


        [Constructable]

        public SkillBallOld()
            : base(6249)
        {

            Movable = false;
            //Name = m_BaseName + Convert.ToString(SkillBonus);
            UpdateName();

        }


        public SkillBallOld(Serial serial)
            : base(serial)
        {

        }


        public override void OnDoubleClick(Mobile from)
        {

            if ((this.SkillBonus == 0) && (from.AccessLevel < AccessLevel.GameMaster))
            {

                from.SendMessage("This Skill Ball isn't charged. Please page for a GM.");

                return;
            }

            else if ((from.AccessLevel >= AccessLevel.GameMaster) && (this.SkillBonus == 0))
            {

                from.SendGump(new PropertiesGump(from, this));

                return;
            }

            if (!IsChildOf(from.Backpack))

                from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.

            else if (!GumpOpen)
            {

                GumpOpen = true;

                from.SendGump(new SkillBallGump(from, this));
            }

            else if (GumpOpen)

                from.SendMessage("You're already using the ball.");
        }
        public void UpdateName()
        {
            if (SkillBonus < 100)
                Name = string.Format("a glowing skillball {0}", SkillBonus);
            if (SkillBonus > 100 && SkillBonus < 200)
                Name = string.Format("a glimmering skillball {0}", SkillBonus);
            if (SkillBonus > 200 && SkillBonus < 300)
                Name = string.Format("a shining skillball {0}", SkillBonus);
            if (SkillBonus > 300 && SkillBonus < 400)
                Name = string.Format("a sparkling skillball {0}", SkillBonus);
            if (SkillBonus > 400 && SkillBonus < 500)
                Name = string.Format("a pulsating skillball {0}", SkillBonus);
            if (SkillBonus > 500 && SkillBonus < 600)
                Name = string.Format("a vibrating skillball {0}", SkillBonus);
            if (SkillBonus > 600 && SkillBonus < 700)
                Name = string.Format("a pulsing skillball {0}", SkillBonus);
            if (SkillBonus > 700 && SkillBonus < 800)
                Name = string.Format("a crackling skillball {0}", SkillBonus);
            if (SkillBonus > 800 && SkillBonus < 900)
                Name = string.Format("a dancing skillball {0}", SkillBonus);
            if (SkillBonus > 900 && SkillBonus < 1000)
                Name = string.Format("a shimmering skillball {0}", SkillBonus);
            if (SkillBonus < 1001)
                Name = string.Format("a superior skillball {0}", SkillBonus);
        }

        public override void Serialize(GenericWriter writer)
        {

            base.Serialize(writer);

            writer.Write((int)0); // version

            writer.Write(m_SkillBonus);

        }


        public override void Deserialize(GenericReader reader)
        {

            base.Deserialize(reader);

            int version = reader.ReadInt();

            switch (version)
            {
                case 0:
                    {
                        m_SkillBonus = reader.ReadInt();
                        break;
                    }
            }
        }
    }
}


namespace Server.Gumps
{

    public class SkillBallGump : Gump
    {

        private const int FieldsPerPage = 14;


        private Skill m_Skill;

        private SkillBallOld m_skb;


        public SkillBallGump(Mobile from, SkillBallOld skb)
            : base(20, 30)
        {

            m_skb = skb;


            AddPage(0);

            AddBackground(0, 0, 260, 351, 5054);


            AddImageTiled(10, 10, 240, 23, 0x52);

            AddImageTiled(11, 11, 238, 21, 0xBBC);


            AddLabel(65, 11, 0, "Skills you can raise");


            AddPage(1);


            int page = 1;

            int index = 0;


            Skills skills = from.Skills;


            int number;

            if (Core.AOS)

                number = 0;

            else

                number = 3;


            for (int i = 0; i < (skills.Length - number); ++i)
            {

                if (index >= FieldsPerPage)
                {

                    AddButton(231, 13, 0x15E1, 0x15E5, 0, GumpButtonType.Page, page + 1);


                    ++page;

                    index = 0;


                    AddPage(page);


                    AddButton(213, 13, 0x15E3, 0x15E7, 0, GumpButtonType.Page, page - 1);

                }

                ///////// FIX
                Skill skill = skills[i];


                if ((skill.Base + m_skb.SkillBonus) <= 100) /////////////////////////////////////////// change this for minimum skill that can be increased. was 100
                {


                    AddImageTiled(10, 32 + (index * 22), 240, 23, 0x52);

                    AddImageTiled(11, 33 + (index * 22), 238, 21, 0xBBC);


                    AddLabelCropped(13, 33 + (index * 22), 150, 21, 0, skill.Name);

                    AddImageTiled(180, 34 + (index * 22), 50, 19, 0x52);

                    AddImageTiled(181, 35 + (index * 22), 48, 17, 0xBBC);

                    AddLabelCropped(182, 35 + (index * 22), 234, 21, 0, skill.Base.ToString("F1"));

                    if (from.AccessLevel >= AccessLevel.Player)

                        AddButton(231, 35 + (index * 22), 0x15E1, 0x15E5, i + 1, GumpButtonType.Reply, 0);

                    else

                        AddImage(231, 35 + (index * 22), 0x2622);
                    ++index;

                }

            }

        }


        public override void OnResponse(NetState state, RelayInfo info)
        {

            Mobile from = state.Mobile;


            if ((from == null) || (m_skb.Deleted))

                return;

            m_skb.GumpOpen = false;


            if (info.ButtonID > 0)
            {

                m_Skill = from.Skills[(info.ButtonID - 1)];


                if (m_Skill == null)

                    return;


                double count = 0;

                for (int i = 0; i < from.Skills.Length; ++i)

                    count += from.Skills[i].Base;


                if ((count + m_skb.SkillBonus) > (from.SkillsCap / 10) && from.AccessLevel < AccessLevel.GameMaster)
                {

                    from.SendMessage("You cannot exceed the skill cap!");

                    return;

                }


                if (m_Skill.Base + m_skb.SkillBonus <= 100)
                {

                    m_Skill.Base += m_skb.SkillBonus;
                    m_skb.UpdateName();
                    m_skb.Delete();

                }

                else 
                    from.SendMessage("You have to choose another skill.");
            }

        }

    }

}